<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <title>睿信教育</title>
  <link rel="stylesheet" href="../dist/lib/framework7/css/framework7.ios.min.css">
  <link rel="stylesheet" href="../dist/lib/framework7/css/framework7.ios.colors.min.css">
  <link rel="stylesheet" href="../dist/css/app.css">
</head>
<body>
<!-- Views -->
<div class="views">
  <div class="view view-main">
    <div class="pages">
      <div data-page="index" class="page page-white">
        <div class="page-content">

          <div class="card">
            <div class="card-content">
              <div class="card-content-inner calendar-card-content">
                <div class="calendar-page-content page-content">
                  <div class="content-block">
                    <div style="padding:0; margin-right:-15px; width:auto" class="content-block-inner">
                      <div id="calendar-inline-container"></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>

        </div>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript" src="../dist/lib/zepto/zepto.min.js"></script>
<script type="text/javascript" src="../dist/lib/framework7/framework7.js"></script>
<script>
var $$ = Dom7;
var myApp = new Framework7();
//工时日历月份变量
var _monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
var _calendarInline;//日历DOM变量
//日历初始化
function workCalendarPage_init() {
  var array = GetStateByDate();
  _calendarInline = myApp.calendar({
    container: '#calendar-inline-container',
    monthNames: _monthNames,
    //dayNamesShort: dayNamesShort,
    value: [new Date()],
    weekHeader: true,
    rangesClasses: [
      //指定某段日期范围可以做一些操作，比如10-1~10-7是国庆可以指定这段日期为一个颜色
    ],
    disabled: {
      //当前时间以前的可点击，当前时间以后的不可点击
      from: new Date()
    },
    toolbarTemplate:
    '<div class="toolbar calendar-custom-toolbar">' +
    '<div class="toolbar-inner">' +
    '<div class="left">' +
    '<a href="#" class="link icon-only"><i class="icon icon-back"></i></a>' +
    '</div>' +
    '<div class="center"></div>' +
    '<div class="right">' +
    '<a href="#" class="link icon-only"><i class="icon icon-forward"></i></a>' +
    '</div>' +
    '</div>' +
    '</div>',
    //日历控件初次加载时调用
    onOpen: function (p) {
      console.log(p);
      $$('.calendar-custom-toolbar .center').text(this.monthNames[p.currentMonth] + ', ' + p.currentYear);
      $$('.calendar-custom-toolbar .left .link').on('click', function () {
        _calendarInline.prevMonth();
      });
      $$('.calendar-custom-toolbar .right .link').on('click', function () {
        _calendarInline.nextMonth();
      });
      SetCalendarValue(p, array);
    },
    //月份改变时调用
    onMonthYearChangeStart: function (p) {
      $$('.calendar-custom-toolbar .center').text(this.monthNames[p.currentMonth] + ', ' + p.currentYear);
      SetCalendarValue(p, array);
    }
    //    ,
    //onDayClick: function (p, dayContainer, year, month, day) {
    //    checkData = calendarInline.value;
    //这样的写法会遇见一个问题就是第一次加载页面的时候当前日期的点击事件不可以使用，需要点击别的日期后再点击当前日期才可以，所以注销这个方法，自己写一个方法
    //}
  });

  //日历某天的点击事件
  $(document).on("click", ".picker-calendar-day", function () {
    GoToWorkEntry(this);
  });
}
workCalendarPage_init();

//跳转工作录入界面
function GoToWorkEntry(dom) {
  if (!$(dom).hasClass('picker-calendar-day-disabled')) {
    loadPage('/WorkTimeManagement/WorkEntry');
  }
}

//获取日期和状态
function GetStateByDate() {
  var array = [
    { state: 'y', date: '2018-10-01' },
    { state: 'y', date: '2018-10-03' },
    { state: 'y', date: '2018-10-29' },
    { state: 'y', date: '2018-10-30' },
    { state: 'n', date: '2018-09-29' },
    { state: 'y', date: '2018-09-05' },
    { state: 'n', date: '2018-11-01' },
    { state: 'y', date: '2018-11-02' },
    { state: 'n', date: '2018-11-04' },
  ];
  return array;
}

//根据返回值设置日历的值
function SetCalendarValue(p, array) {
  $('.picker-calendar-day').removeClass('day-n');
  $('.picker-calendar-day').removeClass('day-y');

  $.each(array, function (index, value) {
    //循环数据库得到的数据对每个数据进行处理
    var curData = new Date(value.date);
    var curYear = curData.getFullYear();
    var curMonth = curData.getMonth() + 1;
    if ((p.currentMonth + 1) == curMonth && p.currentYear == curYear) {
      var curDay = curData.getDate();
      var dom = $('.picker-calendar-day').filter(function (index, value) {
        //筛选当天的数据，根据数据的状态进行当天数据CSS的添加
        var year = $$(value).attr('data-year');
        var month = parseInt($$(value).attr('data-month'), 10) + 1;
        var day = $$(value).attr('data-day');
        //年月日相等，就确定是当天
        if (year == curYear && month == curMonth && day == curDay) {
          return $(value);
        }
      });
      if (value.state == 'y') {
        dom.addClass('day-y');
      } else if (value.state == 'n') {
        dom.addClass('day-n');
      }
    }
  });

}
</script>
</body>
</html>